// pages/consultanteval/consultanteval.js
var app = getApp()
const $api = require('../../utils/api.js').API;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件所需的参数
    navbarData: {
      havebg: 1, //1表示显示    0表示不显示
      out: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '商品列表', //导航栏 中间的标题
      bg: '#fff', //导航背景
    },
    height: app.globalData.height,
    pglist: [
      { num: 1, title: '工作态度', list: [{ title: '责任心', start: 0, }, { title: '积极性', start: 0 }] },
      { num: 2, title: '专业能力', list: [{ title: '业务能力', start: 0, }, { title: '培训指导', start: 0 }] },
      { num: 3, title: '综合评价与建议', },
    ],
    evalData: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    let _this = this
    _this.setData({
      id: options.id
    })
  },
  out(){
    wx.navigateBack({
      delta: 1,
    })
  },
  onInput(e) {
    let evalData = this.data.evalData
    let value = e.detail.value
    let type = e.target.dataset.type
    evalData[type] = value
    this.setData({ evalData })
  },
  //选择营业日期
  onLicenseTime: function (e) {
    this.setData({
      ['evalData.date']: e.detail.value
    })
  },
  onstar(e) {
    console.log(e)
    let _this = this
    let data = e.currentTarget.dataset
    let pglist = _this.data.pglist
    pglist[data.index].list[data.cindex].start = data.start
    _this.setData({
      pglist
    })
  },
  // pglist: [
  //   {num:1, title: '工作态度', list: [{ title:'责任心',start: 0,},{ title:'积极性',start: 0 }] },
  //   {num:2, title: '专业能力', list: [{ title:'业务能力',start: 0,},{ title:'培训指导',start: 0 }] },
  //   {num:3, title: '综合评价与建议', },
  // ]
  onsum() {
    let _this = this
    let pglist = _this.data.pglist
    let evalData = _this.data.evalData
    pglist.forEach((item) => {
      if (item.num == 1) {
        evalData.zrx_star = item.list[0].start
        evalData.jjx_star = item.list[1].start
      }
      if (item.num == 2) {
        evalData.ywnl_star = item.list[0].start
        evalData.pxzd_star = item.list[1].start
      }
    })
    console.log(evalData)
    if (!evalData.dz_name || !evalData.gw_name || !evalData.date || !evalData.dz_name || !evalData.yj_num || !evalData.other_cp) {
      wx.showToast({
        title: '请将信息填写完整',
        icon: 'none',
        duration: 2000
      })
      return
    }
    if (!evalData.zrx_star || !evalData.jjx_star || !evalData.ywnl_star || !evalData.pxzd_star || !evalData.suggest) {
      wx.showToast({
        title: '请将顾问评价填写完整',
        icon: 'none',
        duration: 2000
      })
      return
    }
    evalData.login_token = wx.getStorageSync('login_token')
    evalData.apply_id = _this.data.id
    $api.applyappraise(evalData).then((res) => {
      if (res.data.code == 0) {
        wx.showToast({
          title: res.data.msg,
          icon: 'none',
          duration: 2000
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 1,
          })
        }, 1000)

      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none',
          duration: 2000
        })
      }
    }).catch((err) => {

    })
  }
})